home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 July / macformat52.iso / mac / Shareware Plus / Developers / YAAF v1.0 alpha 1 / Headers / Core / XMenu.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-24  |  5.2 KB  |  214 lines

  1. /*    XMenu.h
  2.  *
  3.  *        This contains the various menu handling classes.
  4.  *
  5.  *    How this works:
  6.  *
  7.  *        Okay, okay, so I really don't make the menu bar into a linked
  8.  *    list of objects totally under my control. Though it certainly would
  9.  *    be a hell of a lot easier.
  10.  *
  11.  *        Instead, I represent the menu bar's structure through using
  12.  *    these structures. Then, when it's time to throw the menu bar up
  13.  *    on the display, I convert the structure into the system's native
  14.  *    menu representation.
  15.  */
  16.  
  17. /*  YAAF - Yet another application framework
  18.  *  Copyright (C) 1997 William Edward Woody and In Phase Consulting
  19.  *  
  20.  *  This library is free software; you can redistribute it
  21.  *  and/or modify it under the terms of the GNU Library
  22.  *  General Public License as published by the Free Software
  23.  *  Foundation; either version 2 of the License, or any
  24.  *  later version.
  25.  *  
  26.  *  This library is distributed in the hope that it will be
  27.  *  useful, but WITHOUT ANY WARRANTY; without even the implied
  28.  *  warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
  29.  *  PURPOSE. See the GNU Library General Public License for
  30.  *  more details.
  31.  *  
  32.  *  You should have received a copy of the GNU Library General
  33.  *  Public License along with this library; if not, write to the
  34.  *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  35.  *  Boston, MA 02111-1307, USA.
  36.  *  
  37.  *  To contact the author, either e-mail me at
  38.  *  woody@alumni.caltech.edu, or write to us at
  39.  *  
  40.  *          William Edward Woody
  41.  *          In Phase Consulting
  42.  *          1545 Ard Eevin Avenue
  43.  *          Glendale, CA 91202
  44.  */
  45.  
  46. #ifndef __XMENU_H__
  47. #define __XMENU_H__
  48.  
  49. #include <XDynArray.h>
  50.  
  51. #if defined(__MWERKS__)
  52.     #if defined(macintosh)
  53.         #pragma options align=power
  54.     #endif
  55.     #if defined(__INTEL__)
  56.         #pragma pack(push,2)
  57.     #endif
  58. #endif
  59.  
  60. /************************************************************************/
  61. /*                                                                        */
  62. /*    Forwards                                                            */
  63. /*                                                                        */
  64. /************************************************************************/
  65.  
  66. class XGFocus;
  67.  
  68. /************************************************************************/
  69. /*                                                                        */
  70. /*    Internal Support Classes                                            */
  71. /*                                                                        */
  72. /************************************************************************/
  73.  
  74. #if OPT_MACOS == 1
  75.  
  76. /*    _MenuIDArray
  77.  *
  78.  *        Because the Macintosh OS doesn't allow me to store command IDs
  79.  *    in the menu bar itself
  80.  */
  81.  
  82. struct _MenuIDArray {
  83.     short                    menuID;            /* ID of this menu            */
  84.     XGDynArray<long>        itemID;            /* The command IDs            */
  85. };
  86.  
  87. #endif
  88.  
  89. /************************************************************************/
  90. /*                                                                        */
  91. /*    Menu Bar Declaration                                                */
  92. /*                                                                        */
  93. /************************************************************************/
  94.  
  95. /*    XGMenuBar
  96.  *
  97.  *        This is an abstraction for a menu bar. A menu bar is the
  98.  *    actual resource, along with methods for modifying the contents.
  99.  *
  100.  *        The menu identifier is an opaque value; it should be treated
  101.  *    as such. On the Macintosh, this is the MenuHandle to the menu being
  102.  *    manipulated; on the PC it's a HMENU, and on X Windows it's God Knows
  103.  *    What.
  104.  *
  105.  *        We assume that the menu bar object is mapped one-to-one with
  106.  *    the actual menu bars used in the application; in most instances,
  107.  *    that means this is a global object, though it doesn't have to be.
  108.  *    (For example, on a multi-window X Windows application, we may have
  109.  *    one of these per window--I don't know.)
  110.  */
  111.  
  112. class XGMenuBar {
  113.     public:
  114.         /*
  115.          *    Construction routines
  116.          */
  117.         
  118. #if OPT_MACOS == 1
  119.                                 XGMenuBar();
  120. #endif
  121.  
  122. #if OPT_WINOS == 1
  123.                                 XGMenuBar(bool,HWND);
  124. #endif
  125.  
  126.         virtual                    ~XGMenuBar();
  127.         
  128.         /*
  129.          *    Resource manipulation
  130.          */
  131.         
  132.         void                    _LoadFromResource(short);
  133.         
  134.         /*
  135.          *    Manipulation of the menus
  136.          */
  137.         
  138.         long                    GetNumMenus();        /* # menus in me    */
  139.         long                    GetMenu(short);        /* Get menu by index*/
  140.         
  141.         /*
  142.          *    Manipulation of the contents (item is zero-based)
  143.          */
  144.                 
  145.         short                    GetNumItems(long);    /* # items in menu    */
  146.  
  147.         void                    SetItemID(long,short,long);
  148.         long                    GetItemID(long,short);
  149.  
  150.         void                    SetItemText(long,short,char *);
  151.         void                    GetItemText(long,short,char *);
  152.         
  153.         void                    SetItemShortcut(long,short,char);
  154.         char                    GetItemShortcut(long,short);
  155.         
  156.         long                    GetSubMenu(long,short);
  157.         
  158.         /*
  159.          *    Insertion/Deletion
  160.          */
  161.         
  162.         void                    InsertMenuItem(long,short);
  163.         void                    DeleteMenuItem(long,short);
  164.                 
  165.         /*
  166.          *    Menu Support
  167.          */
  168.         
  169.         void                    _UpdateMenuBar(XGFocus *);
  170.  
  171. #if OPT_MACOS == 1
  172.         void                    _DispatchCommand(XGFocus *,short,short);
  173. #endif
  174.  
  175.     private:
  176.         /*
  177.          *    Private stuff
  178.          */
  179.          
  180.         short                    fCurResID;
  181.         
  182. #if OPT_MACOS == 1
  183.         _MenuIDArray            *GetMenuArray(short);
  184.         void                    UpdateMenu(XGFocus *,MenuHandle mh);
  185.  
  186.         short                    fApplMenu;
  187.         short                    fApplLen;
  188.         XGDynArray<MenuHandle>    fMenuBar;
  189.         XGDynArray<MenuHandle>    fHidden;
  190.         XGDynArray<_MenuIDArray *> fCommands;        // Mac command codes
  191. #endif
  192.  
  193. #if OPT_WINOS == 1
  194.         bool                    fMDIWindowFlag;
  195.         HMENU                    fMenuHandle;
  196.         HWND                    fMenuWindow;
  197.         
  198.         bool                    IsZoomed();
  199.         int                        UpdatePopUpMenu(XGFocus *, HMENU, short);
  200. #endif
  201. };
  202.  
  203. #if defined(__MWERKS__)
  204.     #if defined(macintosh)
  205.         #pragma options align=reset
  206.     #endif
  207.     #if defined(__INTEL__)
  208.         #pragma pack(pop)
  209.     #endif
  210. #endif
  211.  
  212.  
  213. #endif /* __XMENU_H__ */
  214.